package ysomap.exploits;

import ysomap.common.exception.ArgumentsNotCompleteException;
import ysomap.common.util.Logger;
import ysomap.common.util.Status;
import ysomap.core.util.ReflectionHelper;

/**
 * @author wh1t3P1g
 * @since 2021/6/13
 */
public abstract class AbstractExploit implements Exploit{

    public volatile Status status = Status.INIT;
    public volatile boolean needRunning = false;

    @Override
    public void run() {
        try{
            // check args first, if not complete, throw a ArgumentsNotCompleteException
            ReflectionHelper.checkClassFieldsNotNull(this);
            // check args ok, then do the job
            Logger.success("exploit "+this.getClass().getSimpleName()+" started!");
            work();
            if(!needRunning){
                stop();
                Logger.success("exploit "+this.getClass().getSimpleName()+" done!");
            }
        } catch (ArgumentsNotCompleteException e){
            Logger.normal(e.getMessage());
        }
    }

    @Override
    public void setStatus(Status status) {
        this.status = status;
    }

    @Override
    public boolean isRunning() {
        return status.equals(Status.RUNNING);
    }
}
